class User {
  final String id;
  final String account;
  final String name;
  final String password;
  final String avatar;
  final double balance;

  User({
    required this.id,
    required this.account,
    required this.name,
    required this.password,
    required this.avatar,
    required this.balance
  });

  //从Map<String, dynamic>创建 User对象的工厂构造函数
  //用于从数据库查询结果中读取数据
  factory User.fromMap(Map<String, dynamic> map) {
    return User(
      id: map['id'] as String,
      account: map['account'] as String,
      name: map['name'] as String,
      password: map['password'] as String,
      avatar: map['avatar'] as String? ?? '',
      balance: map['balance'] as double,
    );
  }

  //将User对象转换为Map<String, dynamic>
  //用于将数据插入或更新到数据库中
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'account': account,
      'name': name,
      'password': password,
      'avatar': avatar,
      'balance': balance,
    };
  }
}